using System;
using System.IO;

namespace Pegasus
{
	/// <summary>
	/// Extends the Environment class with .NET system directory properties.
	/// </summary>
	public class EnvironmentEx 
	{
		// Local Static Values
		private static string m_dotNetSystemDirectory = null;
		private static string m_dotNetConfigDirectory = null;


		/// <summary>
		/// Gets the dot net system directory.
		/// </summary>
		/// <value>The dot net system directory.</value>
		public static string DotNetSystemDirectory
		{
			get
			{
				if( m_dotNetSystemDirectory == null )
				{
					m_dotNetSystemDirectory = GetDotNetSystemDirectory();
				}

				return m_dotNetSystemDirectory;
			}
		}

		/// <summary>
		/// Gets the dot net configuration directory.
		/// </summary>
		/// <value>The dot net configuration directory.</value>
		public static string DotNetConfigurationDirectory
		{
			get
			{
				if( m_dotNetConfigDirectory == null )
				{
					m_dotNetConfigDirectory = Path.Combine( EnvironmentEx.DotNetSystemDirectory, "config" );
				}

				return m_dotNetConfigDirectory;
			}
		}

		/// <summary>
		/// Gets the dot net system directory.
		/// </summary>
		/// <returns></returns>
		private static string GetDotNetSystemDirectory()
		{
			string netDir = string.Format( @"{0}\..\Microsoft.NET\Framework\v{1}.{2}.{3}", Environment.SystemDirectory, 
				Environment.Version.Major, Environment.Version.Minor, Environment.Version.Build );

			netDir = Path.GetFullPath( netDir );

			return netDir;
		}
	}
}
